<?php
require_once DIR_APPLICATION . 'controller/abstract.php';

class ControllerStoryContent extends AppController {
      
	public function index() {
            $this->load->model('story/category');
            $this->load->model('story/content');
            $categoryId = (int)$this->request->get['category_id'];
            $page = (int)$this->request->get['page'];
            if ($page <= 0) {
                  $page = 1;
            }

            $total = $this->model_story_category->count($categoryId);
            $limit = $this->model_story_content->getLimit();

            $pagniation = new Pagination();
            $pagniation->total = $total;
            $pagniation->limit = $limit;

            $result = [
                  'rows' => $this->model_story_content->list($categoryId, $page),
                  'pagination' => $pagniation->to_array()
            ];

            $this->jsonSuccess($result);
      }

      public function get() {
            $this->load->model('story/content');
            $storyId = (int)$this->request->get['story_id'];
            $page = (int)$this->request->get['page'];
            if ($page <= 0) {
                  $page = 1;
            }

            $total = $this->model_story_content->count($storyId);
            $result = [
                  'rows' => $this->model_story_content->get($storyId, $page),
                  'total' => (int)$total,
                  'page' => (int)$page
            ];

            $this->jsonSuccess($result);
      }

}